<script type="text/javascript">
    /**
     * 取消采购单
     * @param purId 采购id, 多个使用英文逗号隔开
     */
    function cancelPurchase(purId, fn)
    {
        layer.prompt({
            title: '取消采购单'
            , formType: 2
        }, function(text, index)
        {
            layer.close(index);
            layer.load(0, {shade: false});
            $.post("{:url('cancel')}", {ids: purId, remark: text.trim()}).done(function(response)
            {
                layer.closeAll('loading');
                var icon = response.code == 1 ? 6 : 5;
                layer.msg(response.msg, {icon: icon, time: 3000});
                if(typeof fn === "function") fn(response);
            });
        });
    }

    /**
     * 下单
     * @param purId 采购id, 多个使用英文逗号隔开
     * @param fn 回调函数
     */
    function generateOrder(purId, fn)
    {
        $.get("{:url('business')}", {ids: purId}).done(function(response)
        {
            layer.closeAll('loading');
            var icon = response.code == 1 ? 6 : 5;
            layer.msg(response.msg, {icon: icon, time: 1500});
            if(typeof fn === "function") fn(response);
        });
    }

    /**
     * 申请付款
     * @param purId 采购id
     * @param fn 回调函数
     */
    function generatePayment(purId, fn)
    {
        $.get("{:url('dopayment')}", {ids: purId}).done(function(response)
        {
            layer.closeAll('loading');
            var icon = response.code == 1 ? 6 : 5;
            layer.msg(response.msg, {icon: icon, time: 3000});
            if(typeof fn === "function") fn(response);
        });
    }
</script>